/**   
* @Title: Validate.java
* @Package org.xaoyaoyao.cloud.common.validate
* @Description: TODO
* @author xaoyaoyao
* @date Feb 11, 2019 3:08:03 PM
* @version V1.0   
*/
package org.xaoyaoyao.cloud.common.validate;

import java.io.Serializable;

import org.xaoyaoyao.cloud.common.result.RetCode;
import org.xaoyaoyao.cloud.common.rsp.RetResult;

/**
 * @ClassName: Validate
 * @Description: TODO
 * @author xaoyaoyao
 * @date Feb 11, 2019 3:08:03 PM
 * 
 */
public class Validate implements Serializable {

	private static final long serialVersionUID = -1359444115347380080L;

	public static RetResult<Object> parameterOperationFailed(RetResult<Object> retResult) {
		return makeError(retResult, RetCode.OPERATION_FAILED);
	}

	public static RetResult<Object> makeError(RetResult<Object> retResult, int code) {
		return makeError(retResult, code, "");
	}

	public static RetResult<Object> makeError(RetResult<Object> retResult, int code, Object... args) {
		retResult = null == retResult ? new RetResult<Object>() : retResult;
		retResult.setObjs((null != args && args.length > 0) ? args : null);
		retResult.setCode(code);
		return retResult;
	}

	public static RetResult<Object> parameterRequired(RetResult<Object> retResult, String parameterName) {
		return makeError(retResult, RetCode.PARAMETER_REQUIRED, parameterName);
	}

	public static RetResult<Object> parameterObjectRequired(RetResult<Object> retResult, String parameterName) {
		return makeError(retResult, RetCode.OBJECT_REQUIRED, parameterName);
	}

	public static RetResult<Object> parameterRequired(RetResult<Object> retResult, String objectName, String parameterName) {
		return makeError(retResult, RetCode.OBJECTS_PARAMETER_REQUIRED, objectName, parameterName);
	}

	public static RetResult<Object> parameterMustBeLength(RetResult<Object> retResult, String parameterName, int length) {
		return makeError(retResult, RetCode.MUSTBE_LENGTH, parameterName, length);
	}

	public static RetResult<Object> parameterLength(RetResult<Object> retResult, String parameterName, int minLength, int maxLength) {
		return makeError(retResult, RetCode.ILLEGAL_LENGTH, parameterName, minLength, maxLength);
	}
}
